

from rest_framework.generics import ListAPIView,CreateAPIView
from meiduo_admin.serializers.user_serializers import *
from meiduo_admin.paginators import MyPage

class UserView(ListAPIView, CreateAPIView):
    queryset = User.objects.all()
    serializer_class = UserModelSerializer
    pagination_class = MyPage

    def get_queryset(self):
        # 重写实现根据查询字符串参数keyword过滤
        # TODO: 如何在一个非视图函数中获取，获取请求对象
        # TODO: 答，在非视图函数中通过self.request获取请求对象
        keyword = self.request.query_params.get('keyword')
        if keyword:
            return self.queryset.filter(username__contains=keyword)
        return self.queryset.all()